<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}

$table_er_kami = C::t('#erling_kami_buy#er_kami_buyforapi');

$url_page = ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=erling_kami_buy&pmod=admin_kami_buyforapi';

$page = max(1, intval($page));
$pagesize = max($_GET['pagesize']??20, intval($pagesize));
$start = ($page - 1) * $pagesize;

$expire_time = isset($_GET['expire_time']) ? strtotime($_GET['expire_time']) : TIMESTAMP;
$expire_date = ($expire_time != -1 && is_numeric($expire_time)) ? date('Y-m-d', $expire_time) : '';// 转换为日期格式

$query = [];

if(!empty($_GET['uid'])){
    $query['uid'] = intval($_GET['uid']);
    $url_page .= '&uid='.$_GET['uid'];
}

if(!empty($_GET['kami_key'])){
    $query['kami_key'] = trim($_GET['kami_key']);
    $url_page .= '&kami_key='.urlencode($_GET['kami_key']);
}

if(!empty($_GET['order_no'])){
    $query['order_no'] = trim($_GET['order_no']);
    $url_page .= '&order_no='.urlencode($_GET['order_no']);
}

if(!empty($_GET['expire_time'])){
    $url_page .= '&expire_time='.$_GET['expire_time'];
}

$result = $table_er_kami->fetch_all($page, $pagesize, $query, $expire_time);

$kami_list = $result['data'];
$total = $result['total'];

if(!empty($_GET['pagesize'])){
    $url_page.= '&pagesize='.intval($_GET['pagesize']);
}
$multipage = multi($total, $pagesize, $page, $url_page);

// 积分类型
$extcredits_array = DB::fetch_all("SELECT * FROM %t WHERE skey LIKE %s", array('common_setting', 'extcredits%'));
if ($extcredits_array && isset($extcredits_array[0]['svalue'])) {
    $extcredits_data = unserialize($extcredits_array[0]['svalue']);
} else {
    $extcredits_data = [];
}

include template('erling_kami_buy:admin_kami_buyforapi');